import React, { useEffect, useMemo, useState } from 'react';
import { Form, message } from 'antd';

import authHelpr from '@/utils/auth/helper';

import { withRoutePage } from '@/utils/enhanceUtils';

import OverviewPage from './ExcelExportCollect/OverviewPage';
import DetailPage from './ExcelExportDetail/DetailPage';

const { checkCode } = authHelpr;

const ExcelImport = props => {
    const { location } = props;
    const { query = {} } = location;
    const [pageTabs, setPageTabs] = useState(checkCode('finance:salary:computation:send:export:collect') ? 'overview' : 'detail');

    const pagePower = useMemo(() => !checkCode('finance:salary:computation:send:export:collect') && !checkCode('finance:salary:computation:send:export:detail'), []);

    if (pagePower) {
        message.error('检测到无对应页面权限，请确认权限配置！')
    }


    useEffect(() => {
        const { tabs } = query;
        if (tabs) {
            setPageTabs(tabs);
        }
    }, [query]);

    // eslint-disable-next-line no-nested-ternary
    return pagePower ? null : (pageTabs === 'overview' ? <OverviewPage pageType={pageTabs} /> : <DetailPage pageType={pageTabs} />)
};

export default withRoutePage(Form.create({ name: 'excelForm' })(ExcelImport));
